$(function(){
	//底层弹出框
	var str = '<i class="mui-pull-right mui-icon mui-icon-arrowright"></i>';
	//上班时间点击
	$('#choiceToWorkTime').on('tap',function(){
		var picker = new mui.PopPicker({
		    layer: 2
		});
		var oldTiem = $('.toWorkTime-cont').text().split(':');
		var pickerIndex0 = parseInt(oldTiem[0]);//获取小时的层级
		var pickerIndex1 = parseInt(oldTiem[1]);//获取分钟的层级
		picker.setData(createHour());//数据导入
		picker.pickers[0].setSelectedIndex(pickerIndex0);
		picker.pickers[1].setSelectedIndex(pickerIndex1);
		picker.show(function(SelectedItem) {
			layer.open({
			    content: '修改成功！'
			    ,skin: 'msg'
			    ,time: 2 //2秒后自动关闭
			});
			var hour = SelectedItem[0].value;
			var minute = SelectedItem[1].value;
			var dateStr = hour + ':' + minute + str;
			$("[name=work_shift]").val(hour + ':' + minute);
			$('.toWorkTime-cont').html(dateStr);
		})
	})
	$('#choiceOffWorkTime').on('tap',function(){
		var picker = new mui.PopPicker({
		    layer: 2
		});
		var oldTiem = $('.offWorkTime-cont').text().split(':');
		var pickerIndex0 = parseInt(oldTiem[0]);//获取小时的层级
		var pickerIndex1 = parseInt(oldTiem[1]);//获取分钟的层级
		picker.setData(createHour());//数据导入
		picker.pickers[0].setSelectedIndex(pickerIndex0);
		picker.pickers[1].setSelectedIndex(pickerIndex1);
		picker.show(function(SelectedItem) {
			layer.open({
			    content: '修改成功！'
			    ,skin: 'msg'
			    ,time: 2 //2秒后自动关闭
			});
			var hour = SelectedItem[0].value;
			var minute = SelectedItem[1].value;
			var dateStr = hour + ':' + minute + str;
			$("[name=closing_time]").val(hour + ':' + minute);
			$('.offWorkTime-cont').html(dateStr);
		})
	});
	$('#choiceAttenTime').on('tap',function(){
		var index = layer.open({
			shadeClose: false,
		    content: '<div class="atten-box">'+
		    			'<div class="mui-poppicker-header"><a class="mui-btn mui-poppicker-btn-cancel quxiao">取消</a><a class="mui-btn mui-btn-blue mui-poppicker-btn-ok queding">确定</a><div class="mui-poppicker-clear"></div></div>'+	
		    			'<div class="atten-cont">'+
		    				'<ul>'+
		    					'<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">星期一</span><span class="mui-pull-right">休息</span></li>'+
		    					'<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">星期二</span><span class="mui-pull-right">休息</span></li>'+
		    					'<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">星期三</span><span class="mui-pull-right">休息</span></li>'+
		    					'<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">星期四</span><span class="mui-pull-right">休息</span></li>'+
		    					'<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">星期五</span><span class="mui-pull-right">休息</span></li>'+
		    					'<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">星期六</span><span class="mui-pull-right">休息</span></li>'+
		    					'<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">星期日</span><span class="mui-pull-right">休息</span></li>'+
		    				'</ul>'+
		    			'</div>'+
		    			'<div>'
		    ,skin: 'footer'
		 });
		 $('.quxiao').on('tap',function(){
		 	layer.close(index);
		 });
		 $('.queding').on('tap',function(){
		  	var li = $('.atten-cont').find('.active').parent();
		  	console.log(li);
		  	var dateText = '星期 ';
		  	var $str = '';
		  	$.each(li, function(i,v) {
		  		// console.log(v);
		  		if(i != 0){
		  			dateText += '、';
		  		}
		  		dateText += $(v).find('.mui-pull-left').eq(1).text().split('星期')[1];
		  		if($(v).find('.mui-pull-left').eq(1).text().split('星期')[1]=='一'){
					$str +='1,'
				}else if($(v).find('.mui-pull-left').eq(1).text().split('星期')[1]=='二'){
		  			$str +='2,'
				}else if($(v).find('.mui-pull-left').eq(1).text().split('星期')[1]=='三'){
                    $str +='3,'
                }else if($(v).find('.mui-pull-left').eq(1).text().split('星期')[1]=='四'){
                    $str +='4,'
                }else if($(v).find('.mui-pull-left').eq(1).text().split('星期')[1]=='五'){
                    $str +='5,'
                }else if($(v).find('.mui-pull-left').eq(1).text().split('星期')[1]=='六'){
                    $str +='6,'
                }else if($(v).find('.mui-pull-left').eq(1).text().split('星期')[1]=='天'){
                    $str +='0,'
                }
		  	});
		  	$("[name=attendance]").val($str);
		  	$('.attendanceDate-cont').html(dateText + '<i class="mui-pull-right mui-icon mui-icon-arrowright"></i>');
		 	layer.close(index);
		 });
		  $('.atten-cont i').on('tap',function(){
		  	var span = $(this).parents('li').find('.mui-pull-right');
		  	if($(this).is('.active')){
		  		$(this).removeClass('active');
		  		$(span).text('休息');
		  		
		  	}else{
		  		$(this).addClass('active');
		  		var toCont = $('.toWorkTime-cont').text();
	  			var offCont = $('.offWorkTime-cont').text();
		  		var time = toCont + '-' + offCont;
		  		$(span).text(time);
		  	}
		  })
	});
	//时间界限
    // $('#late_time').on('tap',function(){
     //    var index = layer.open({
     //        shadeClose: false,
     //        content: '<div class="atten-box">'+
     //        '<div class="mui-poppicker-header"><a class="mui-btn mui-poppicker-btn-cancel quxiao">取消</a><a class="mui-btn mui-btn-blue mui-poppicker-btn-ok queding">确定</a><div class="mui-poppicker-clear"></div></div>'+
     //        '<div class="atten-cont">'+
     //        '<ul>'+
     //        '<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">小于30分钟</span></li>'+
     //        '<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">小于60分钟</span></li>'+
     //        '<li><i class="mui-pull-left xuanzhong iconfont">&#xe83b;</i><span class="mui-pull-left">大于60分钟</span></li>'+
     //        '</ul>'+
     //        '</div>'+
     //        '<div>'
     //        ,skin: 'footer'
     //    });
     //    $('.quxiao').on('tap',function(){
     //        layer.close(index);
     //    });
     //    $('.queding').on('tap',function(){
     //        var li = $('.atten-cont').find('.active').parent();
     //        console.log(li);
     //        var dateText = '星期 ';
     //        $.each(li, function(i,v) {
     //            if(i != 0){
     //                dateText += '、';
     //            }
     //            dateText += $(v).find('.mui-pull-left').eq(1).text().split('星期')[1];
    //
     //            console.log(dateText);
    //
     //        });
     //        $('.attendanceDate-cont').html(dateText + '<i class="mui-pull-right mui-icon mui-icon-arrowright"></i>');
     //        layer.close(index);
     //    });
     //    $('.atten-cont i').on('tap',function(){
     //        var span = $(this).parents('li').find('.mui-pull-right');
     //        if($(this).is('.active')){
     //            $(this).removeClass('active');
     //            $(span).text('休息');
    //
     //        }else{
     //            $(this).addClass('active');
     //            var toCont = $('.toWorkTime-cont').text();
     //            var offCont = $('.offWorkTime-cont').text();
     //            var time = toCont + '-' + offCont;
     //            $(span).text(time);
     //        }
     //    })
    // });
	//创建小时方法
	function createHour(){
		var dateTiemHour = [];
		for(var i = 0;i<24;i++){
			var value = (i < 10 ? '0'+ i : i).toString();//得到分钟输入
			var dateTimeHourJson = {'value':value,'text':value+'时','children':createMinute()};
			dateTiemHour.push(dateTimeHourJson);
		}
		return dateTiemHour;
	}
	//创建分钟方法
	function createMinute(){
		var dateTiemMinute = [];
		for(var j = 0;j<60;j++){
			var value = (j < 10 ? '0'+ j : j).toString();//得到分钟输入
			var dateTiemMinuteJson = {'value': value,'text':j + '分'};
			dateTiemMinute.push(dateTiemMinuteJson);
		}
		return dateTiemMinute;
	}
})
